package com.netease.nim.chatroom.demo.education.activity;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.netease.nim.chatroom.demo.R;
import com.netease.nim.chatroom.demo.base.ui.TActivity;
import com.netease.nim.chatroom.demo.im.config.UserPreferences;

/**
 * Created by hzxuwen on 2016/3/15.
 */
public class SettingActivity extends TActivity{
    private RadioGroup strategyGroup;
    private RadioButton lowLatencyButton;
    private RadioButton antiJitterButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setting_activity);

        findViews();
    }

    private void findViews() {
        strategyGroup = (RadioGroup) findViewById(R.id.player_strategy);
        lowLatencyButton = (RadioButton) findViewById(R.id.low_latency);
        antiJitterButton = (RadioButton) findViewById(R.id.anti_jitter);

        if (UserPreferences.getPlayerStrategy() == 0) {
            lowLatencyButton.setChecked(true);
        } else {
            antiJitterButton.setChecked(true);
        }

        strategyGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.anti_jitter) {
                    UserPreferences.setPlayerStrategy(false);
                } else if (checkedId == R.id.low_latency) {
                    UserPreferences.setPlayerStrategy(true);
                }
            }
        });
    }
}
